/*
    XTU OJ: 1131
    by: fifth_light
*/

#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>

int results[1000050] = {0};
int table[1000050] = {0};

int check_num(int num) {
    /*
        stage:
        0 -> 下降中
        1 -> 上升中
    */
    int i = 1, stage = 0, last_num = 10;
    while (1) {
        if (i > num) {
            break;
        }
        int digit = (num / i) % 10;
        if (last_num != 10) {
            if (stage == 0) {
                if (digit > last_num) {
                    if (i == 10) {
                        return 0;
                    } else {
                        stage = 1;
                    }
                } else if (digit == last_num) {
                    return 0;
                }
            } else {
                if (digit <= last_num) {
                    return 0;
                }
            }
        }
        last_num = digit;
        i *= 10;
    }
    return stage == 1;
}

void prepare_table() {
    for (int i = 100; i < 1000050; i++) {
        table[i] = check_num(i);
    }
    int res = 0;
    for (int i = 100; i < 1000050; i++) {
        results[i] = (res += table[i]);
    }
}

int num_count(int start, int end) {
    if (start > end) {
        int tmp = end;
        end = start;
        start = tmp;
    }
    return results[end] - results[start] + (table[start] ? 1 : 0);
}

int main(void) {
    prepare_table();
    int t;
    scanf("%d", &t);
    for(int i = 0; i < t; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        printf("%d\n", num_count(a, b));
    }
    return 0;
}
